<?php
 /**
 * 
 * 
 * recursively searches for a given filename from location called
 * returns false if not found and path otherwise
 * @param string $path
 * @param string $file
 * @return mixed  
 */
function checkDirectory( $path, $file ){
    $check = glob( $path . '*' );
    
    foreach ( $check as $filename) {
    	if( $file == "View" ){
    	}
        if( is_dir($filename) ){
            $test = checkDirectory( "$filename".DIRECTORY_SEPARATOR, $file );
            if( $test != false ){
                return $test;
            }
        }
        else {
        	$testword = explode( ".",array_pop( explode(DIRECTORY_SEPARATOR,$filename) ) );
        	   if( $testword[0] ==  $file ){ 
                return $filename; 
        	   }
         }

    }
    return false;
}

/**
 * 
 * the simplest autoloader function
 * @param string $class_name
 */
function classloader($class_name) {
	       global $CONFIG;
	       $path = false;
           if( empty( $CONFIG['paths'] ) || !is_array($CONFIG['paths'])){
           	 return false;
           }
			foreach ($CONFIG['paths'] as $path_to_check ){
				if( !$path ){
				$path = checkDirectory( $path_to_check ,$class_name );
				}
			}
           if(  $path  ){
           require_once $path;
           }
           else {

    }
}


?>